home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d26
/
cattest.arc
/
EVALTEST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-07-01
|
3KB
|
85 lines
{$A+,B-,D+,E+,F-,I+,L+,N-,O-,R-,S+,V+}
{$M 16384,0,655360}
USES
CRT,UTILITY,EVAL3,checkans;
CONST
fn_char_set = ['a','b','s','r','o','u','n','d',
't','c','q','i','h','l','g','p','f','e','x'];
VAR
My_2nd_Formula,
MyFormula : STRING;
MyValue : real;
MyErrorPosition : Integer;
MyErrorType : Integer;
MyErrMsg : STRING;
Escaped : Boolean;
posvar : Integer;
BEGIN {evaltest, MAIN entry}
Randomize;
REPEAT
MyFormula := '';
ClrScr;
Our_Write(1,1,'Testing EVAL3 for numerical formulii.');
MyFormula := Read_Equation(1,25,79,'Enter the formula("?" to halt).',
fn_char_set);
IF MyFormula[1] <> '?'
THEN
BEGIN
Evaluate(MyFormula,MyValue,MyErrorPosition,MyErrMsg);
IF MyErrorPosition <> 0
THEN Our_Write(1,2,'Error');
IF (MyErrorPosition <> 0) AND (MyErrorType = 0)
THEN
Our_Write(1,2,'not finished with expression evaluation');
WriteLn(MyValue); {This is not a string, hence writeLN}
Pause(1,25,'Press any key to continue.');
END;
UNTIL MyFormula[1] = '?';
REPEAT
MyFormula := '';
ClrScr;
Our_Write(1,1,'Testing EVAL3 for text based formulii.');
REPEAT
Our_Write(1,2,
'Enter the character to be used as a variable("?" to halt).');
ReadLn(variable);
if variable = '?' then halt;
UNTIL variable IN ['a'..'z','A'..'Z'];
uc_var := UpCase(variable);
IF uc_var = variable
THEN lc_var := Chr(Ord(variable) - Ord('A')+Ord('a'))
ELSE lc_var := variable;
MyFormula := Read_Equation(1,25,79,
'Enter the formula using '+variable+' ("?" to halt).',
fn_char_set);(*variables already included*)
IF MyFormula[1] = '?'
THEN halt;
{ first lower case the string }
FOR posvar :=1 TO Length(Myformula) DO
IF (MyFormula[posvar] >= 'A') AND (MyFormula[posvar] <= 'Z')
THEN
MyFormula[posvar] := Chr(Ord(MyFormula[posvar]) + Ord('a') - Ord('A'));
Our_Write(1,4,MyFormula);
My_2nd_Formula := Read_Equation(1,25,79,'Enter the formula("?" to halt).',
fn_char_set);(*variables already included*)
IF My_2nd_Formula[1] = '?'
THEN halt;
{ first lower case the string }
FOR posvar:=1 TO Length(My_2nd_Formula) DO
IF (My_2nd_Formula[posvar] >= 'A') AND (My_2nd_Formula[posvar] <= 'Z')
THEN
MyFormula[posvar] := Chr(Ord(MyFormula[posvar]) + Ord('a') - Ord('A'));
Our_Write(1,5,My_2nd_Formula);
IF Check_Answer(MyFormula,My_2nd_Formula,0.001)
THEN
Our_Write(1,3,'Formulas are equal.')
ELSE
Our_Write(1,3,'Formulas are NOT equal.');
Pause(1,25,'Press any key to continue.');
UNTIL MyFormula[1] = '?';
END.